<?php

namespace App\Admin\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
use App\Common\Services\Common;

class AdminPaytypeList extends Model
{
    protected $table = 'admin_paytype_list';
    public $timestamps = false;
    protected $primaryKey = 'id';
    protected $guarded = ['_token'];

    /**
     *获取列表 
     */
    public static function getList(Request $request)
    {
        $query = self::where(['is_del' => 1])->orderBy('create_at', 'desc');

        $type = $request->type ?? 0;
        $isgetall = intval($request->isgetall) ?? 0;
        if (in_array($type, [1, 2])) {
            $query->where('type', $type);
        }
        $paytype_name = $request->paytype_name;
        if ($paytype_name != '') {
            $query->where('paytype_name', 'like', '%' . $paytype_name . '%');
        }
        if ($isgetall == 0) {
            $limit = $request->limit ?? 10;
            $list = $query->paginate($limit)->toArray();
            return Common::paginateDataToArray($list);
        } else {
            $list = $query->get()->toArray();
            return ['list' => $list];
        }
    }
}
